package com.oddpointcc.szpt.accounting.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ErrorController {

	@RequestMapping("/errors")
	public String renderErrorPage(Model model, HttpServletRequest request) {
		String errorMsg = "";
		int httpErrorCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
		switch (httpErrorCode) {
		case 400: {
			errorMsg = "当前请求无法被服务器理解";
			break;
		}
		case 401: {
			errorMsg = "当前请求需要用户验证";
			break;
		}
		case 403: {
			errorMsg = "你没有权限访问";
			break;
		}
		case 404: {
			errorMsg = "该页面未被找到";
			break;
		}
		case 500: {
			errorMsg = "服务器内部错误";
			break;
		}
		}
		model.addAttribute("errorMsg", errorMsg);
		model.addAttribute("errorCode", httpErrorCode);
		return "errors";
	}

}